import cv2 as cv


def main():
    cap = cv.VideoCapture(0)
    fourcc = cv.VideoWriter_fourcc(*'H264')
    out = cv.VideoWriter('../data/output.mp4', fourcc, 20.0, (640, 480))

    while True:
        ret, frame = cap.read()
        out.write(frame)
        cv.imshow('Press Q to exit', frame)
        if cv.waitKey(1) == ord('q'):
            break

    cap.release()
    out.release()
    cv.destroyAllWindows()


if __name__ == "__main__":
    main()
